package com.boot2.core.utils;

import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
 * @author zhangweilin
 * @Description: 通用判断工具
 * @date 2020/6/24
 */
public class CheckUtil {

    public static boolean isNotEmpty(String str) {
        return StringUtils.isNotEmpty(str);
    }

    public static boolean isNotEmpty(Collection<?> collection) {
        return !CollectionUtils.isEmpty(collection);
    }

    public static boolean isNotEmpty(Map<?, ?> map) {
        return !CollectionUtils.isEmpty(map);
    }

    public static boolean isNotEmpty(Set<?> set) {
        return set != null && !set.isEmpty();
    }

    public static boolean isNotEmpty(byte[] bytes) {
        return bytes != null && bytes.length > 0;
    }

    public static boolean isNotEmpty(short[] t) {
        return t != null && t.length > 0;
    }

    public static boolean isNotEmpty(int[] t) {
        return t != null && t.length > 0;
    }

    public static boolean isNotEmpty(long[] t) {
        return t != null && t.length > 0;
    }

    public static boolean isNotEmpty(String[] t) {
        return t != null && t.length > 0;
    }

    public static boolean isNotEmpty(Object[] t) {
        return t != null && t.length > 0;
    }

    /**
     * 数组中所有的不为空
     * @param objArr
     * @return
     */
    public static boolean areNotEmpty(Object... objArr) {
        if (null == objArr) {
            return false;
        }
        boolean flag = true;
        for (int i = 0; i < objArr.length; i++) {
            Object obj = objArr[i];
            //遇到一个为空的就返回false
            if (obj instanceof String) {
                String obj1 = (String) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Collection) {
                Collection<?> obj1 = (Collection<?>) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Map) {
                Map<?,?> obj1 = (Map<?,?>) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Set<?>) {
                Set<?> obj1 = (Set<?>) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof byte[]) {
                byte[] obj1 = (byte[]) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof short[]) {
                short[] obj1 = (short[]) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof int[]) {
                int[] obj1 = (int[]) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof long[]) {
                long[] obj1 = (long[]) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof String[]) {
                String[] obj1 = (String[]) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Object[]) {
                Object[] obj1 = (Object[]) obj;
                flag = isNotEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }
        }
        return flag;
    }


    //============以下为取反
    public static boolean isEmpty(String str) {
        return !isNotEmpty(str);
    }

    public static boolean isEmpty(Collection<?> collection) {
        return !isNotEmpty(collection);
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return !isNotEmpty(map);
    }

    public static boolean isEmpty(Set<?> set) {
        return !isNotEmpty(set);
    }

    public static boolean isEmpty(byte[] bytes) {
        return !isNotEmpty(bytes);
    }

    public static boolean isEmpty(short[] t) {
        return !isNotEmpty(t);
    }

    public static boolean isEmpty(int[] t) {
        return !isNotEmpty(t);
    }

    public static boolean isEmpty(long[] t) {
        return !isNotEmpty(t);
    }

    public static boolean isEmpty(String[] t) {
        return !isNotEmpty(t);
    }

    public static boolean isEmpty(Object[] t) {
        return !isNotEmpty(t);
    }


    /**
     * 数组中所有的为空
     * @param objArr
     * @return
     */
    public static boolean areEmpty(Object... objArr) {
        if (null == objArr) {
            return false;
        }
        boolean flag = true;
        for (int i = 0; i < objArr.length; i++) {
            Object obj = objArr[i];
            //遇到一个为空的就返回false
            if (obj instanceof String) {
                String obj1 = (String) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Collection) {
                Collection<?> obj1 = (Collection<?>) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Map) {
                Map<?,?> obj1 = (Map<?,?>) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Set<?>) {
                Set<?> obj1 = (Set<?>) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof byte[]) {
                byte[] obj1 = (byte[]) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof short[]) {
                short[] obj1 = (short[]) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof int[]) {
                int[] obj1 = (int[]) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof long[]) {
                long[] obj1 = (long[]) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof String[]) {
                String[] obj1 = (String[]) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }

            if (obj instanceof Object[]) {
                Object[] obj1 = (Object[]) obj;
                flag = isEmpty(obj1);
                if (!flag) {
                    return flag;
                }
            }
        }
        return flag;
    }


}
